# -*- coding: utf-8 -*-
from celery import Celery
from tank import app as flask_app

from . import settings

flask_app.config.from_object(settings)


def make_celery(app):
    celery_app = Celery(app.import_name, backend=app.config['CELERY_BACKEND'], broker=app.config['CELERY_BROKER_URL'])
    celery_app.conf.update(app.config)

    class ContextTask(celery_app.Task):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                return celery_app.Task.__call__(self, *args, **kwargs)

    celery_app.Task = ContextTask
    return celery_app


celery = make_celery(flask_app)


@celery.task()
def add_together(a, b):
    return a + b
